package ES6.demo;

import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.ArrayList;
import java.util.List;

/**
 * 暂未完成，不能用
 * Created by dong on 2018/4/25.
 */
public class SuggestUtils {

    public static List getSuggestList(String indexName, String type, String text, String... fieldNames){
        TransportClient client = ESUtils.getClient();
//        String input = "60"
//        String clusterName = "";
//        String esHosts = "";
//        Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.sniff", true).put("cluster.name", clusterName).put("node.client", true).build();
//        Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(esHosts, 9300));
//        String field = "nameSuggest";

//        Client client = ElasticClientFactory.getClient();
        SearchRequestBuilder req = client.prepareSearch(indexName);
        req.setQuery(QueryBuilders.matchAllQuery());
//        SuggestionBuilder csfb = new CompletionSuggestionBuilder("body").text(text).size(100);//sug是提示器的名字，可以有多个suggest
//        req.suggest(csfb);
//        SearchResponse suggestResponse = req.execute().actionGet();
//        List<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>> results = suggestResponse.getSuggest().getSuggestion("sug").getEntries();
//        System.out.println(JSON.toJSONString(suggestResponse));
//        for (Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option> op : results) {
//            Text text = op.getText();
//            System.out.println(text.toString());
//            List<? extends Suggest.Suggestion.Entry.Option> options = op.getOptions();
//            for (Suggest.Suggestion.Entry.Option pp : options) {
//                System.out.println("\t" + pp.getText() + "==>" + pp.getScore());
//            }
//        }
        return new ArrayList();
    }
}
